using Naptime.Dlc;
using UnityEngine.UI;
using Voodoo.GameOps;
using Voodoo.Pattern;

public class SkinBuyButton : BuyButton
{
	public override void Fill(Item item, bool useCurrency = true, bool showLevel = false)
	{
		base.Fill(item, useCurrency, showLevel);
		if (!activeIcon.TryGetComponent<Image>(out var component))
		{
			return;
		}
		bool flag = costText.color == tooExpensiveColor;
		if (flag)
		{
			component.color = ActivityUtility.UNACTIVE;
		}
		else if (Singleton<DLCManager>.Instance.IsSkinDlc(_item))
		{
			if (_item.ItemType == ItemType.Skin && InventoryManager.Instance.CurrentlySelected(ItemType.Skin) == _item)
			{
				component.color = ActivityUtility.UNACTIVE;
				return;
			}
			flag = !Singleton<DLCManager>.Instance.IsSkinUnlocked(_item);
			component.color = (flag ? ActivityUtility.UNACTIVE : ActivityUtility.ACTIVE);
		}
		else
		{
			if (!InventoryManager.Instance.HasInventory(_item))
			{
				flag = _item.ItemType != 0 || InventoryManager.Instance.CurrentlySelected(ItemType.Skin) == _item;
			}
			component.color = (flag ? ActivityUtility.UNACTIVE : ActivityUtility.ACTIVE);
		}
	}

	public override void OnClick()
	{
		if (!_item.isPartOfDLC || Singleton<DLCManager>.Instance.IsSkinUnlocked(_item))
		{
			if (InventoryManager.Instance.HasInventory(_item) && _item.GetPrice() <= SingletonMB<GameManager>.Instance.PrestigePoints)
			{
				InventoryManager.Instance.SpendPrestigePoints(_item.GetPrice());
				InventoryManager.Instance.UnlockItem(_item);
				OnClicked?.Invoke();
				SingletonMB<SkinContainer>.Instance.Refresh();
			}
			if (InventoryManager.Instance.IsUnlocked(_item))
			{
				InventoryManager.Instance.SelectItem(_item);
				SingletonMB<SkinContainer>.Instance.Refresh();
			}
		}
	}
}
